/**
 * ____________________ *
 *  ____ ____ ____ _  _ *
 *  |___ [__] |--< |\/| *
 * ____________________ *
 *
 * THE CORM PROJECT
 *
 * This file may only be used in accordance with the
 * terms of the Academic Free License ("AFL") v. 3.0,
 * as published by the Open Software Initiative.  A
 * copy of this license is provided in this source
 * release, and may be viewed online at:
 *
 * (http://www.opensource.org/licenses/afl-3.0.php)
 */
package org.eremite.corm.party;

import org.eremite.corm.BaseArchetype;
import org.eremite.corm.party.address.AssociatedAddress;
import org.eremite.corm.party.relationship.Capability;
import org.eremite.corm.party.relationship.PartyRole;

import javax.persistence.*;
import java.util.*;

@Entity
public class Party extends BaseArchetype {

    @OneToMany(cascade={
            CascadeType.PERSIST,
            CascadeType.MERGE,
            CascadeType.REMOVE}, mappedBy="party")
    private Set <AssociatedAddress> addresses = new HashSet <AssociatedAddress> ();

//    private long preferredAddressID;

    @OneToMany(cascade={
            CascadeType.PERSIST,
            CascadeType.MERGE,
            CascadeType.REMOVE})
    private Set <Binding> bindings = new HashSet <Binding> ();

    @OneToMany(cascade={
            CascadeType.PERSIST,
            CascadeType.MERGE,
            CascadeType.REMOVE})
    private Set <RegisteredIdentifier> registeredIds =
            new HashSet <RegisteredIdentifier> ();

    @OneToMany(cascade={
            CascadeType.PERSIST,
            CascadeType.MERGE,
            CascadeType.REMOVE})
    private Set <Capability> capabilities = new HashSet<Capability>();

    @OneToMany(cascade={
            CascadeType.PERSIST,
            CascadeType.MERGE,
            CascadeType.REMOVE}, mappedBy="party")
    private Set <PartyRole> roles = new HashSet <PartyRole> ();

    /* Default Zero-arg Constructor */
    public Party() {}

    public Set<AssociatedAddress> getAddresses() {
        return addresses;
    }

    public void setAddresses(Set<AssociatedAddress> addresses) {
        this.addresses = addresses;
    }

//    public long getPreferredAddressID() {
//        return preferredAddressID;
//    }
//
//    public void setPreferredAddressID(long address) {
//        this.preferredAddressID = address;
//    }

    public Set<Binding> getPreferences() {
        return bindings;
    }

    public void setPreferences(Set<Binding> preferences) {
        this.bindings = bindings;
    }

    public Set<RegisteredIdentifier> getRegisteredIdentifiers() {
        return registeredIds;
    }

    public void setRegisteredIdentifiers(Set<RegisteredIdentifier> registeredIds) {
        this.registeredIds = registeredIds;
    }

    public Set<PartyRole> getPartyRoles() {
        return roles;
    }

    public void setPartyRoles(Set<PartyRole> roles) {
        this.roles = roles;
    }

    public Set<Capability> getCapabilities() {
        return this.capabilities;
    }

    public void setCapabilities(Set<Capability> capabilities) {
        this.capabilities = capabilities;
    }

    public void addPartyRole(PartyRole ... roles) {
        getPartyRoles().addAll(Arrays.asList(roles));
    }

    public void addPartyRole(PartyRole role) {
        getPartyRoles().add(role);
    }
    
    public void addRegisteredIdentifier(RegisteredIdentifier rid) {
        getRegisteredIdentifiers().add(rid);
    }

    public void addRegisteredIdentifier(RegisteredIdentifier ... rids) {
        getRegisteredIdentifiers().addAll(java.util.Arrays.asList(rids));
    }

    public void addPreference(Binding ... bindings) {
        getPreferences().addAll(Arrays.asList(bindings));
    }

    public void addBinding(Binding binding) {
        getPreferences().add(binding);
    }

    public void addCapability(Capability ... capabilities) {
        getCapabilities().addAll(Arrays.asList(capabilities));
    }

    public void addCapability(Capability capability) {
        getCapabilities().add(capability);
    }

    public void addAddress(AssociatedAddress ... addresses) {
        getAddresses().addAll(Arrays.asList(addresses));
    }

    public void addAddress(AssociatedAddress address) {
        getAddresses().add(address);
    }
}